import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
// 前台状态管理
function sessionStg(state) {
  window.sessionStorage.setItem("state", JSON.stringify(state));
}
export default new Vuex.Store({
  state: {
    isLogin: false, // 是否登录
    info: {}
  },
  actions: {
    resetState(context) {
      context.commit("resetState");
    },
    changeLoginStatus(context, login) {
      context.commit("changeLoginStatus", login);
    },
    changeInfo(context, info) {
      context.commit("changeInfo", info);
    }
  },
  mutations: {
    resetState(state) {
      let obj = {
        isLogin: false // 是否登录
      };
      Object.assign(state, obj);
      sessionStg(state);
    },
    changeLoginStatus(state, login) {
      state.isLogin = login;
      sessionStg(state);
    },
    changeInfo(state, info) {
      state.info = info;
      sessionStg(state);
    }
  }
});
